<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Java Web框架：Struts 2 初见 | 坤个人博客</title><meta name="author" content="Houkl"><meta name="copyright" content="Houkl"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="引言：  在Java Web应用程序开发中，一直使用servlet原生方式执行请求，为了极大的提高开发效率以及代码质量，从而选择我们今天的主角Struts 2！作为一款成熟、功能强大的Java Web框架，一直备受开发者的青睐。本文将深入探索Struts 2框架的特性、优势以及如何在实际项目中应用。 Struts 2的核心特性 MVC架构：Struts 2采用经典的Model-View-Cont">
<meta property="og:type" content="article">
<meta property="og:title" content="Java Web框架：Struts 2 初见">
<meta property="og:url" content="http://hkl.gitee.io/houkl/2015/09/19/struts/struts2/index.html">
<meta property="og:site_name" content="坤个人博客">
<meta property="og:description" content="引言：  在Java Web应用程序开发中，一直使用servlet原生方式执行请求，为了极大的提高开发效率以及代码质量，从而选择我们今天的主角Struts 2！作为一款成熟、功能强大的Java Web框架，一直备受开发者的青睐。本文将深入探索Struts 2框架的特性、优势以及如何在实际项目中应用。 Struts 2的核心特性 MVC架构：Struts 2采用经典的Model-View-Cont">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s1.ax1x.com/2023/05/31/p9vLcwT.png">
<meta property="article:published_time" content="2015-09-18T16:00:00.000Z">
<meta property="article:modified_time" content="2015-09-18T16:00:00.000Z">
<meta property="article:author" content="Houkl">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s1.ax1x.com/2023/05/31/p9vLcwT.png"><link rel="shortcut icon" href="/houkl/img/favicon.png"><link rel="canonical" href="http://hkl.gitee.io/houkl/2015/09/19/struts/struts2/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/houkl/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/houkl/',
  algolia: undefined,
  localSearch: {"path":"/houkl/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Java Web框架：Struts 2 初见',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2015-09-19 00:00:00'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = 'hidden';
    document.getElementById('loading-box').classList.remove("loaded")
  }
}

preloader.initLoading()
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://s1.ax1x.com/2023/05/31/p9v6spQ.md.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/houkl/archives/"><div class="headline">文章</div><div class="length-num">21</div></a><a href="/houkl/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/houkl/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><hr/></div></div><div class="post" id="body-wrap"><header class="not-top-img" id="page-header"><nav id="nav"><span id="blog-info"><a href="/houkl/" title="坤个人博客"><span class="site-name">坤个人博客</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav></header><main class="layout" id="content-inner"><div id="post"><div id="post-info"><h1 class="post-title">Java Web框架：Struts 2 初见</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2015-09-18T16:00:00.000Z" title="发表于 2015-09-19 00:00:00">2015-09-19</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2015-09-18T16:00:00.000Z" title="更新于 2015-09-19 00:00:00">2015-09-19</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/houkl/categories/Struts/">Struts</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Java Web框架：Struts 2 初见"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div><article class="post-content" id="article-container"><p><a target="_blank" rel="noopener" href="https://imgse.com/i/p9vLcwT"><img src="https://s1.ax1x.com/2023/05/31/p9vLcwT.png" alt="p9vLcwT.png"></a></p>
<p>引言： </p>
<p>在Java Web应用程序开发中，一直使用servlet原生方式执行请求，为了极大的提高开发效率以及代码质量，从而选择我们今天的主角Struts 2！作为一款成熟、功能强大的Java Web框架，一直备受开发者的青睐。本文将深入探索Struts 2框架的特性、优势以及如何在实际项目中应用。</p>
<h2 id="Struts-2的核心特性"><a href="#Struts-2的核心特性" class="headerlink" title="Struts 2的核心特性"></a>Struts 2的核心特性</h2><ol>
<li>MVC架构：Struts 2采用经典的Model-View-Controller（MVC）架构模式，将应用程序分为模型、视图和控制器三个组件，使代码结构更清晰、可维护性更高。</li>
<li>拦截器：Struts 2基于拦截器（Interceptor）机制，可以在请求的不同阶段执行自定义的逻辑，例如验证、日志记录、权限控制等。开发人员可以通过配置和定制拦截器栈，灵活地处理请求。</li>
<li>标签库：Struts 2提供丰富的标签库（Tag Library），简化了前端页面的开发。这些标签可以用于生成表单、显示数据、处理国际化等常见的Web开发任务，减少了大量的HTML编写工作。</li>
<li>表单验证：Struts 2内置了强大的表单验证机制，可以轻松地对用户输入进行验证和校验。开发人员可以使用预定义的验证规则（如非空、范围检查、正则表达式等），也可以自定义验证器。</li>
<li>数据绑定：Struts 2支持将请求参数自动绑定到Java对象的属性上，简化了表单数据的处理过程。开发人员只需定义合适的模型对象，就可以自动完成数据绑定和类型转换。</li>
<li>国际化和本地化：Struts 2提供了强大的国际化（Internationalization）和本地化（Localization）支持。开发人员可以轻松地实现多语言界面，根据用户的地区设置显示不同的语言和格式。</li>
<li>REST支持：Struts 2提供了对RESTful风格的Web服务的支持。开发人员可以通过简单的配置和注解，将Struts 2应用程序暴露为RESTful接口，实现资源的创建、读取、更新和删除操作。</li>
<li>插件扩展：Struts 2提供了丰富的插件扩展机制，允许开发人员根据自己的需求扩展框架功能。例如，可以使用插件来集成其他框架、增加新的拦截器、扩展标签库等。</li>
</ol>
<h2 id="MVC架构在Struts-2中的应用"><a href="#MVC架构在Struts-2中的应用" class="headerlink" title="MVC架构在Struts 2中的应用"></a>MVC架构在Struts 2中的应用</h2><ol>
<li>模型（Model）层：<ul>
<li>模型层负责处理业务逻辑和数据操作。在Struts 2中，模型通常是一个POJO（Plain Old Java Object）或JavaBean对象，用于封装数据。</li>
<li>模型层可以与数据库进行交互，执行数据访问操作（例如查询、更新等）。</li>
<li>开发人员可以使用Java的持久层框架（如Hibernate、IBatis）或直接使用JDBC等技术与数据库进行交互。</li>
</ul>
</li>
<li>视图（View）层：<ul>
<li>视图层负责展示用户界面和接收用户的输入。</li>
<li>在Struts 2中，视图通常由JSP（JavaServer Pages）或FreeMarker等模板引擎生成，用于呈现动态内容。</li>
<li>视图层可以通过Struts 2的标签库（如Struts Tags、JSTL）来生成表单、显示数据等，简化页面开发过程。</li>
</ul>
</li>
<li>控制器（Controller）层：<ul>
<li>控制器层负责处理用户请求和控制应用程序的流程。</li>
<li>在Struts 2中，控制器由Action类扮演，它们接收用户请求并根据请求的类型执行相应的操作。</li>
<li>控制器从视图层接收用户输入，通过模型层进行业务处理，并将结果返回给视图层进行展示。</li>
<li>控制器通过配置的方式（如struts.xml文件）来将请求路由到正确的Action类进行处理。</li>
</ul>
</li>
</ol>
<h3 id="Struts-2与前端技术的整合"><a href="#Struts-2与前端技术的整合" class="headerlink" title="Struts 2与前端技术的整合"></a>Struts 2与前端技术的整合</h3><ol>
<li>使用标签库：Struts 2提供了丰富的标签库（如Struts Tags、Form Tags、UI Tags等），用于生成HTML表单、显示数据、处理分页、国际化等常见的前端任务。这些标签库可以简化页面开发，提高开发效率。</li>
<li>使用Ajax技术：Struts 2与Ajax技术的整合可以实现页面的异步加载和交互。开发人员可以使用Struts 2提供的Ajax标签库（如sj:xxx标签）或自定义Ajax请求，与后台进行数据交互，实现无刷新的页面更新和动态效果。</li>
<li>整合JavaScript框架：开发人员可以使用各种流行的JavaScript框架（如jQuery等）与Struts 2进行整合。通过在页面中引入JavaScript库，可以利用其丰富的功能和组件来增强用户界面的交互性和视觉效果。</li>
<li>RESTful接口：Struts 2支持将应用程序暴露为RESTful接口，可以与前端的JavaScript框架或移动应用进行交互。开发人员可以使用Struts 2的注解（如@Result、@Actions等）和配置，定义RESTful风格的接口，实现资源的创建、读取、更新和删除操作。</li>
</ol>
<h3 id="以下是一个简单的示例代码"><a href="#以下是一个简单的示例代码" class="headerlink" title="以下是一个简单的示例代码"></a>以下是一个简单的示例代码</h3><ol>
<li>创建一个名为”struts2-demo”的Java Web项目，并在项目的src目录下创建一个名为”struts.xml”的文件。</li>
<li>在项目的WebContent目录下创建一个名为”index.jsp”的文件，作为应用程序的首页。</li>
<li>在WebContent目录下创建一个名为”WEB-INF”的文件夹，并在其中创建一个名为”lib”的文件夹，用于存放Struts 2相关的库文件。</li>
<li>将Struts 2的相关库文件（如struts2-core.jar、struts2-convention-plugin.jar等）复制到”WEB-INF&#x2F;lib”文件夹中。</li>
<li>在web.xml文件中进行以下配置：</li>
</ol>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">web-app</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">display-name</span>&gt;</span>Struts2 Demo<span class="tag">&lt;/<span class="name">display-name</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">&lt;!-- 配置Struts 2的核心过滤器 --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">filter</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">filter-name</span>&gt;</span>struts2<span class="tag">&lt;/<span class="name">filter-name</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">filter-class</span>&gt;</span>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter<span class="tag">&lt;/<span class="name">filter-class</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">filter</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">filter-mapping</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">filter-name</span>&gt;</span>struts2<span class="tag">&lt;/<span class="name">filter-name</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">url-pattern</span>&gt;</span>/*<span class="tag">&lt;/<span class="name">url-pattern</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">filter-mapping</span>&gt;</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">&lt;!-- 配置欢迎页 --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">welcome-file-list</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">welcome-file</span>&gt;</span>index.jsp<span class="tag">&lt;/<span class="name">welcome-file</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">welcome-file-list</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">web-app</span>&gt;</span></span><br></pre></td></tr></table></figure>

<ol start="6">
<li>在”struts.xml”文件中进行以下配置，定义一个简单的Action：</li>
</ol>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">struts</span> <span class="keyword">PUBLIC</span></span></span><br><span class="line"><span class="meta">        <span class="string">&quot;-//Apache Software Foundation//DTD Struts Configuration 2.5//EN&quot;</span></span></span><br><span class="line"><span class="meta">        <span class="string">&quot;http://struts.apache.org/dtds/struts-2.5.dtd&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">struts</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">package</span> <span class="attr">name</span>=<span class="string">&quot;default&quot;</span> <span class="attr">extends</span>=<span class="string">&quot;struts-default&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">action</span> <span class="attr">name</span>=<span class="string">&quot;hello&quot;</span> <span class="attr">class</span>=<span class="string">&quot;com.example.HelloAction&quot;</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">result</span>&gt;</span>/hello.jsp<span class="tag">&lt;/<span class="name">result</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">action</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">package</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">struts</span>&gt;</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol start="7">
<li>创建一个名为”HelloAction.java”的Java类，放置在com.example包下，实现HelloAction的逻辑：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.example;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">HelloAction</span> &#123;</span><br><span class="line">  <span class="keyword">public</span> String <span class="title function_">execute</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;success&quot;</span>;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol start="8">
<li>创建一个名为”hello.jsp”的JSP页面，用于显示欢迎消息：</li>
</ol>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>Hello Struts 2<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">h1</span>&gt;</span>Hello, Struts 2!<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>完成以上步骤后，你可以将该项目部署到支持Java Web的Servlet容器中（如Tomcat），启动容器，并访问应用程序的首页（例如：<a target="_blank" rel="noopener" href="http://localhost:8080/struts2-demo/%EF%BC%89%E3%80%82">http://localhost:8080/struts2-demo/）。</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://hkl.gitee.io/houkl">Houkl</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://hkl.gitee.io/houkl/2015/09/19/struts/struts2/">http://hkl.gitee.io/houkl/2015/09/19/struts/struts2/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://hkl.gitee.io/houkl" target="_blank">坤个人博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://s1.ax1x.com/2023/05/31/p9vLcwT.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/houkl/2016/05/21/srping/spring/" title="解密Spring的IOC、DI和AOP：让你的代码焕发新生"><img class="cover" src="https://s1.ax1x.com/2023/05/31/p9xEKDU.png" onerror="onerror=null;src='/houkl/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">解密Spring的IOC、DI和AOP：让你的代码焕发新生</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://s1.ax1x.com/2023/05/31/p9v6spQ.md.jpg" onerror="this.onerror=null;this.src='/houkl/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Houkl</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/houkl/archives/"><div class="headline">文章</div><div class="length-num">21</div></a><a href="/houkl/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/houkl/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/houkunliang"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">个人博客不定期更新，还望各位看官谅解</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Struts-2%E7%9A%84%E6%A0%B8%E5%BF%83%E7%89%B9%E6%80%A7"><span class="toc-number">1.</span> <span class="toc-text">Struts 2的核心特性</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#MVC%E6%9E%B6%E6%9E%84%E5%9C%A8Struts-2%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8"><span class="toc-number">2.</span> <span class="toc-text">MVC架构在Struts 2中的应用</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Struts-2%E4%B8%8E%E5%89%8D%E7%AB%AF%E6%8A%80%E6%9C%AF%E7%9A%84%E6%95%B4%E5%90%88"><span class="toc-number">2.1.</span> <span class="toc-text">Struts 2与前端技术的整合</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%A5%E4%B8%8B%E6%98%AF%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E7%9A%84%E7%A4%BA%E4%BE%8B%E4%BB%A3%E7%A0%81"><span class="toc-number">2.2.</span> <span class="toc-text">以下是一个简单的示例代码</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/houkl/2019/06/28/java/volatile/" title="深入理解Java中的volatile关键字"><img src="https://s1.ax1x.com/2023/06/06/pCiS2tJ.png" onerror="this.onerror=null;this.src='/houkl/img/404.jpg'" alt="深入理解Java中的volatile关键字"/></a><div class="content"><a class="title" href="/houkl/2019/06/28/java/volatile/" title="深入理解Java中的volatile关键字">深入理解Java中的volatile关键字</a><time datetime="2019-06-27T16:00:00.000Z" title="发表于 2019-06-28 00:00:00">2019-06-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/houkl/2019/04/03/java/reentrantLock/" title="深入探索Java中的ReentrantLock"><img src="https://s1.ax1x.com/2023/06/06/pCiSafs.png" onerror="this.onerror=null;this.src='/houkl/img/404.jpg'" alt="深入探索Java中的ReentrantLock"/></a><div class="content"><a class="title" href="/houkl/2019/04/03/java/reentrantLock/" title="深入探索Java中的ReentrantLock">深入探索Java中的ReentrantLock</a><time datetime="2019-04-02T16:00:00.000Z" title="发表于 2019-04-03 00:00:00">2019-04-03</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/houkl/2019/01/26/java/rushToPurchase/" title="用Redis + Lua 实现商品抢购"><img src="https://s1.ax1x.com/2023/06/06/pCiSgk4.png" onerror="this.onerror=null;this.src='/houkl/img/404.jpg'" alt="用Redis + Lua 实现商品抢购"/></a><div class="content"><a class="title" href="/houkl/2019/01/26/java/rushToPurchase/" title="用Redis + Lua 实现商品抢购">用Redis + Lua 实现商品抢购</a><time datetime="2019-01-25T16:00:00.000Z" title="发表于 2019-01-26 00:00:00">2019-01-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/houkl/2018/12/15/java/synchronized/" title="深入了解 Java 中的 Synchronized 关键字"><img src="https://s1.ax1x.com/2023/06/06/pCPzDde.png" onerror="this.onerror=null;this.src='/houkl/img/404.jpg'" alt="深入了解 Java 中的 Synchronized 关键字"/></a><div class="content"><a class="title" href="/houkl/2018/12/15/java/synchronized/" title="深入了解 Java 中的 Synchronized 关键字">深入了解 Java 中的 Synchronized 关键字</a><time datetime="2018-12-14T16:00:00.000Z" title="发表于 2018-12-15 00:00:00">2018-12-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/houkl/2018/11/05/middleware/activeMQ/" title="ActiveMQ初见"><img src="https://s1.ax1x.com/2023/06/06/pCPxUHg.png" onerror="this.onerror=null;this.src='/houkl/img/404.jpg'" alt="ActiveMQ初见"/></a><div class="content"><a class="title" href="/houkl/2018/11/05/middleware/activeMQ/" title="ActiveMQ初见">ActiveMQ初见</a><time datetime="2018-11-04T16:00:00.000Z" title="发表于 2018-11-05 00:00:00">2018-11-05</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By Houkl</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/houkl/js/utils.js"></script><script src="/houkl/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/houkl/js/search/local-search.js"></script></div></div></body></html>